<?php
// $Id$

/**
 * Controller_Admin_Web 控制器
 */
class Controller_Admin_team extends Controller_Abstract {
	
	/**
	 * 团队管理
	 */
	function actionIndex()
	{
	    
	   // Acctuser::getdainumbyuid(1, 0);
	    $acctname = $this->_context->acctname;
	    $realname = $this->_context->realname;
	    $user1 = new Acctuser();
	    $user2 = new Acctuser();
	    if($acctname){
	        $user1 = Acctuser::find('acctname = ?',$acctname)->getOne();
	    }
	    if($realname){
	        $user2 = Acctuser::find('realname = ?',$realname)->getOne();
	    }
	    
	    $user = $user1->id()?$user1:$user2;
	    if($user->id()){
	        $uid = $user->id;
	    }else{
	        $uid = 0;
	    }
	    
	    $teamsql = "select count(id) from acct_user where find_in_set({$uid},team_tag)";
	    $sumRecord =  QDB::getConn()->execute($teamsql)->fetchOne();
	    
	    $this->curr_page= isset($this->_context->page)?intval($this->_context->page):1;
	    $pagination['record_count'] = $sumRecord;
	    $pagination['page_count'] = ceil($sumRecord/$this->page_size);
	    $pagination['first'] = 1;
	    $pagination['last'] = $pagination['page_count'];
	    $pagination['next'] = $this->curr_page+1;
	    $pagination['prev'] = $this->curr_page-1;
	    $pagination['current'] = $this->curr_page;
	    $pagination['page_base'] = $this->curr_page*$this->page_size;
	   
	    
	    $this->get_param();
	    $item = Acctuser::find('find_in_set(?,team_tag)',$uid)->limitPage($this->curr_page,$this->page_size)->getAll();	

	    $this->_view['item'] = $item;
	    $this->_view['uid'] = $uid;
	    $this->_view['acctname'] = $acctname;
	    $this->_view['realname'] = $realname;
	    $this->_view['pagination'] = $pagination;
	    $this->_view['orderField'] = $this->orderkey;
	    $this->_view['orderDirection'] = $this->ordertype;
	}
}


